﻿using UnityEngine;

namespace XLua_Ki
{
    public class GameManager_Ki : MonoBehaviour
    {
        static ResourcesManager_Ki m_ResourcesManager;
        static PanelManager_Ki m_PanelManager;
        static AudioManager_Ki m_AudioManager;
        static PoolManager_Ki m_PoolManager;
        static ObjectManager_Ki m_ObjectManager;

        private XLua.LuaEnv luaEnv;
        public XLua.LuaEnv LuaEnv
        {
            get { return luaEnv; }
            set { luaEnv = value; }
        }

        public static GameManager_Ki Instance;
        private void Awake()
        {
            Initialize();
        }

        private void Initialize()
        {
            Instance = this;
            luaEnv = new XLua.LuaEnv();

            string LuaScript_str = @"
            --require xxxPanel.lua.txt
            function doluafile(filePath, ...)
                dofile(filePath)
            end

            print('init luaEnv')";

            luaEnv.DoString(LuaScript_str);

            //添加Manager
            m_PanelManager = gameObject.AddComponent<PanelManager_Ki>();
            m_ResourcesManager = gameObject.AddComponent<ResourcesManager_Ki>();
            m_AudioManager = gameObject.AddComponent<AudioManager_Ki>();
            m_PoolManager = gameObject.AddComponent<PoolManager_Ki>();
            m_ObjectManager = gameObject.AddComponent<ObjectManager_Ki>();
        }

        /// 获取PanelManager的脚本对象.
        public PanelManager_Ki GetPanelManager_Ki()
        {
            return m_PanelManager;
        }

        /// 获取ResourcesManager的脚本对象.
        public ResourcesManager_Ki GetResourcesManager_Ki()
        {
            return m_ResourcesManager;
        }

        /// 获取AudioManager的脚本对象.
        public AudioManager_Ki GetAudioManager_Ki()
        {
            return m_AudioManager;
        }

        /// 获取PoolManager的脚本对象.
        public PoolManager_Ki GetPoolManager_Ki()
        {
            return m_PoolManager;
        }

        /// 获取ObjectManager的脚本对象
        public ObjectManager_Ki GetObjectManager_Ki()
        {
            return m_ObjectManager;
        }
    }
}
